<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of index
 *
 * @author chema_000
 */
class Admin_Controllers_Index extends Libs_Controller {
    public function __construct() {
        parent::__construct();
    }
    
    public function index() {
        $model_user = new Admin_Models_tblUsers();

        if (isset($_POST['btnLogin'])) {
//            if (isset($_POST['confirm']) && $_POST['confirm'] != $_SESSION['security_code']) {
//                $this->view->render('index/index');
//            }

            $admin = $model_user->checkLogin($_POST['txtUser'],md5( $_POST['txtPass']) );
            if ($admin != null) {
                $_SESSION['user_id'] = $admin->getId();
                $_SESSION['user_admin'] = $admin->getEmail();
                $_SESSION['full_name_admin'] = $admin->getName();
                header("location: admin/home");
            } 
        }
        $this->view->render('index/index');
    }

    public function logout() {
        session_destroy();
        session_unset();
        $this->view->render('index/logout');
    }

    public function home() {
        $model_user = new Admin_Models_tblUsers();
        $this->view->listAllUser = $model_user->getAllUsers();
        $this->view->render('index/home');
    }
}
